home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / rTutors / part2 / rTutor.cc next >
Encoding:
C/C++ Source or Header  |  1990-05-17  |  4.9 KB  |  131 lines  |  [TEXT/pdos]

  1. /* PROGRAM R.Tutor  ( a home-grown tutorial for writing applications using resources */
  2. /* Part 1 - starting up & shutting down the tools from a ToolStartup List kept in a resource */
  3. /* Part 2 - add a menu bar that is kept in a resource */
  4.  
  5. #include <types.h>
  6. #include <INTMATH.h>
  7. #include <MEMORY.h>
  8. #include <MISCTOOL.h>
  9. #include <LOCATOR.h>
  10. #include <DESK.H>
  11. #include <QUICKDRAW.h>
  12. #include <EVENT.h>
  13. #include <CONTROL.h>
  14. #include <WINDOW.h>    
  15. #include <MENU.h>    
  16.  
  17.  
  18. #define  kStartStopID    1L    /* used when starting and shutting down tools */
  19.  
  20. /*---------------------- Menus & Menu Bars ---------------------------*/
  21. #define  kMenuBarID      1L   /* resource ID of the menu bar itself */
  22.  
  23.     /* define all the menu id's */
  24. #define  kAppleMenuID   1000L  /* resource ID of the Apple menu */
  25. #define  kFileMenuID    2000L  /* resource ID of the File menu */
  26. #define  kEditMenuID    3000L  /* resource ID of the Edit menu */
  27.  
  28.     /* now, define the menu item id's */
  29. #define   kAboutBoxID   1001L  /* resource ID of the About Box menu item */ 
  30.  
  31. #define   kNewItemID    2001L  /* resource ID of the New Item in File menu */
  32. #define   kOpenItemID   2002L  /* resource ID of the Open item in File menu */ 
  33. #define   kCloseItem     255L  /* the "Close" item */
  34. #define   kSaveItem     2004L  /* the "Save" item */
  35. #define   kSaveAsItem   2005L  /* the "Save As..." item */
  36. #define   kRevertItem   2006L  /* the "Revert to Saved" item */
  37. #define   kPageItem     2007L  /* the "Page Setup..." item */
  38. #define   kPrintItem    2008L  /* the "Print..." item */
  39. #define   kQuitItem     2009L  /* the "Quit" item */
  40.  
  41. #define   kUndoItem      250L  /* the "Undo" item */
  42. #define   kCutItem       251L  /* the "Cut" item */
  43. #define   kCopyItem      252L  /* the "Copy" item */
  44. #define   kPasteItem     253L  /* the "Paste" item */
  45. #define   kClearItem     254L  /* the "Clear" item */
  46. #define   kSelectItem   3001L  /* the "Select All" item */
  47. #define   kShowClipItem 3002L  /* the "Show ClipBoard" item */
  48.  
  49.  
  50.     
  51. /* declare all of the global variables that we'll be using */    
  52. unsigned   gMyMemID;    /* holds the ID returned by MMStartup */
  53. Ref       gToolListRef; /* the list of tools used to start and stop the tools */
  54. Boolean   gPunt;        /* TRUE if it's time to quit the app */
  55.  
  56.  
  57.  
  58.  
  59. /* ------------------------------------------------------------------------ */
  60. /* the following procedure installs the menu bar from a resource */
  61.  
  62. do_make_menus()
  63.    MenuBarRecHndl my_mbar_hndl;
  64.    word menu_bar_height; 
  65.   { 
  66.  
  67.    /* the next three calls are ALL required to bring the menu bar in from */
  68.    /* the resource fork AND make it the current system menu bar.  For */
  69.    /* details, see the IIGS Toolbox Reference, under NewMenuBar2  */
  70.   my_mbar_hndl = NewMenuBar2(refIsResource, kMenuBarID, nil); 
  71.   SetSysBar(my_mbar_hndl); 
  72.   SetMenuBar(nil);
  73.  
  74.    /* now, add NDA's, adjust the sizes of the menus, and draw the menu bar */
  75.    /* note the casting to "word" for kAppleMenuID!  FixAppleMenu needs a word */
  76.    /* but most places need resource ID's to be longs, so the constant is */
  77.    /* defined as a LONG and cast to a WORD here - this is a MAJOR pain to */
  78.    /* debug if you don't know about it! */
  79.   FixAppleMenu((word)kAppleMenuID); /* adds NDA's */
  80.   menu_bar_height =  FixMenuBar(); /* adjust the sizes */
  81.   DrawMenuBar();  /* draw the new menu bar and enjoy! */ 
  82.   }
  83. }
  84.  
  85. /* ------------------------------------------------------------------------ */
  86. /* the following procedure is responsible for starting the tools (using the */
  87. /* list in a resource) if the SartupTools call fails, then gPunt will */
  88. /* contain "TRUE", so we can abort the app the global variable for this app's */
  89. /*  memory id is acquired here as well. */
  90.  
  91. do_init_rom() /* on the GS, start up the tools here */
  92. {
  93.     gMyMemID = _ownerid; /* find out our memory id & save it for later */
  94.  
  95.     /* crank 'em up! */
  96.     gToolListRef = StartUpTools(gMyMemID,refIsResource,kStartStopID);
  97.     
  98.     if (_toolErr == noError)
  99.       {      /* there was no error, so the app can continue starting up */
  100.         gPunt = FALSE;
  101.       }
  102.     else
  103.       {     /* something went wrong, so set gPunt to indicate the failure */
  104.         gPunt = TRUE;
  105.       }
  106. }
  107.  
  108.  
  109.  
  110. /* ------------------------------------------------------------------------ */
  111. /* the following procedure is the main application itself. */
  112. /* don't forget to add the code that will check the message center to see if */
  113. /* this app was launched by clicking on its icon or by clicking on a data */
  114. /* file created by this app.  If the data file was clicked on, then grab its */
  115. /* name out of the message center and open it instead of opening the */
  116. /* untitled window. */
  117.  
  118. main()
  119. {    
  120.     do_init_rom();    /* get my memory id, start the tools, & set gPunt */
  121.     if (gPunt == FALSE)
  122.       {
  123.         do_make_menus();  /* insert the menu bar */
  124.         SysBeep();
  125.         SysBeep();
  126.         SysBeep();
  127.       }
  128.     ShutDownTools(refIsHandle,gToolListRef); /* shut down the tools and quit */
  129. } /* end of main program */
  130.